package com.lanou.pianke.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lanou.pianke.common.entity.PiankeResult;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import sun.misc.BASE64Encoder;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

public class JsoupUtils {

    // 不带参数的url
    public static String getData(String url) {
        Connection connect = Jsoup.connect(url);
        System.out.println("connect: "+connect);
        String data = null;
        try {
            data = connect.ignoreContentType(true).timeout(5000).execute().body();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return data;
    }

    // 带参数的url
    public static String getData(String url, Map<String, Object> params) {
        String paramsStr = "";
        for (Map.Entry<String, Object> param : params.entrySet()) {
            paramsStr += param.getKey();
            paramsStr += "=";
            paramsStr += param.getValue();
            paramsStr += "&";
        }
        url = url + "?" + paramsStr;

        return getData(url);
    }

}
